<template>
  <van-nav-bar left-text="返回" left-arrow @click-left="onClickLeft">
  </van-nav-bar>
  <van-form>
    <van-cell-group inset>
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        readonly
      />
      <van-field @click="torestpwd" label="重置账号密码" readonly is-link />
    </van-cell-group>
    <div style="margin: 16px">
      <van-button round block type="primary" @click="onlogout" color="#7232dd">
        退出登陆
      </van-button>
    </div>
  </van-form>
</template>

<script setup>
import { useRoute, useRouter } from "vue-router";
import { ref, onMounted } from "vue";
import { logout, tokenInfo } from "@/api/user";
const router = useRouter();
const username = ref("");

onMounted(() => {
  tokenInfo().then((res) => {
    if (res.code == 200) {
      console.log(res);
      username.value = res.data.loginId;
    } else {
      showNotify({ type: "warning", position: "bottom", message: res.msg });
    }
  });
});
function onClickLeft() {
  //返回上一页
  router.back();
}
function onlogout() {
  //退出登录
  logout().then((res) => {
    if (res.code == 200) {
      localStorage.removeItem("username");
      localStorage.removeItem("ward");
      router.push("/login");
    } else {
      showNotify({ type: "warning", position: "bottom", message: res.msg });
    }
  });
}

function torestpwd() {
  router.push("/restpwd");
}
</script>

<style></style>
